Repository navigation
Proof of concept for running a PHP script without Docker - #9164
Conversation
…ker into task/scriptrunner
…ker into task/scriptrunner
… mode to scripts. Introduced `hasExplicitReturn` method to determine return statements in scripts. Updated core service task configuration to set default execution mode to 'bare' and added migration for `execution_mode` column in scripts and script_versions tables. Expanded PermissionSeeder to include 'run-in-process-modules' permission. Added unit tests for legacy result variable and explicit scalar return handling in ScriptRuntime.
…cks. Implemented `authorizeModulesExecution` method in `ScriptController` to manage execution modes. Updated `Script` model to include `execution_mode` property and validation rules. Introduced `ScriptExecutionModeResolver` service for determining execution modes. Enhanced UI to allow selection of execution mode in script editing. Added tests for execution mode functionality and authorization checks.
PR SummaryMedium Risk Overview Resolver and runtime: Authorization and import: New UI: Script edit screen exposes execution mode when modules are enabled and the user is allowed. Tests cover API fallbacks, import behavior, resolver rules, and runtime return semantics. Reviewed by Cursor Bugbot for commit 963bc36. Bugbot is set up for automated code reviews on this repo. Configure here. |
…roduced `canUseModules` method for streamlined permission validation in `ScriptController`, `ScriptExporter`, and `TestScript`. Updated tests to ensure non-privileged users fall back to bare execution mode when duplicating or editing scripts. Enhanced `ScriptRuntime` to handle nested return statements correctly.
| return Script::EXECUTION_MODE_BARE; | ||
| } | ||
|
|
||
| $mode = $script->execution_mode ?: config('core-service-task.execution', Script::EXECUTION_MODE_BARE); |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: HIGH
Description: A process import can persist a falsy script execution_mode (empty string or "0") with allow_in_process true. ScriptExecutionModeResolver treats that falsy value as config('core-service-task.execution'). When that setting is modules and modules_enabled is on, ScriptRunner and CoreServiceTask include the package PHP inside the Laravel worker. The new run-in-process-modules check only recognizes the exact string modules, so an importer who lacks that permission and is not an administrator still reaches worker execution.
Impact: This bypasses the permission this PR adds around trusted in-worker PHP. A user who only has import-processes can store attacker-controlled PHP that later runs in the application worker, with registered ScriptRuntime modules, the worker's privileges, every EnvironmentVariable copied into the process environment, and an API token for the script run-as user. That is full control of the app process. It matters only when CORE_SERVICE_TASK_ENABLED, CORE_SERVICE_TASK_MODULES_ENABLED, and CORE_SERVICE_TASK_EXECUTION=modules are set. The execution default is bare, and per-script modules already works without that env var, but execution=modules is a documented mode and the resolver uses it as the fallback. The script runs when the imported process is started (start is a separate process-policy check the package can satisfy); import itself does not launch it. Preview is unaffected: TestScript forces bare when the current user lacks run-in-process-modules.
Remediation: In ScriptExecutionModeResolver, treat only the exact string modules as modules. Map null, empty string, "0", and every other value to bare, and do not consult core-service-task.execution for that decision. In ScriptExporter::import, set execution_mode to bare unless the value is exactly modules and canUseModules() is true. Apply that normalization before the first Importer save.
…mportController and ImportV2. Refactor ScriptExporter to utilize the importing user ID for permission checks. Update execution mode handling in ScriptController to default to bare mode. Add tests for import behavior based on user authorization and execution mode preservation. Improve ScriptRuntime to handle nested curly braces correctly.
…Extracted logic for handling tokens and brace management into dedicated methods. Updated unit tests to reflect changes in helper function syntax.
…property to facilitate permission checks in API tests, ensuring proper authorization during script execution tests.
|




Added per-script execution modes with bare as the default and optional modules execution for trusted PHP scripts. Added migration, resolver, permissions, UI selection, module gating, and test coverage while preserving Docker/microservice execution and legacy $result scripts.
variables .env
scripts
CORE_SERVICE_TASK_ENABLED=true
CORE_SERVICE_TASK_MODULES_ENABLED=true
CORE_SERVICE_TASK_EXECUTION=bare